package com.lanyan.system.controller.system;

import java.math.BigDecimal;
import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lanyan.common.annotation.Log;
import com.lanyan.common.core.controller.BaseController;
import com.lanyan.common.core.domain.AjaxResult;
import com.lanyan.common.enums.BusinessType;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import com.lanyan.system.domain.OrdersItem;
import com.lanyan.system.service.IOrdersItemService;
import com.lanyan.common.utils.poi.ExcelUtil;
import com.lanyan.common.core.page.TableDataInfo;

/**
 * 订单详情Controller
 *
 * @author lanyan
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/ordersItem")
public class OrdersItemController extends BaseController
{
    @Autowired
    private IOrdersItemService ordersItemService;

    /**
     * 查询订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:ordersItem:list')")
    @GetMapping("/list")
    @ApiImplicitParams({
          @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
          @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "ordersId", value = "所属订单", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "skuId", value = "所属规格", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "name", value = "名称", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "skuName", value = "规格名", dataType = "String", dataTypeClass = String.class),
          @ApiImplicitParam(name = "price", value = "单价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
          @ApiImplicitParam(name = "num", value = "数量", dataType = "Long", dataTypeClass = Long.class),
          @ApiImplicitParam(name = "pageNum", value = "第几页", dataType = "int", dataTypeClass = int.class),
          @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", dataTypeClass = int.class),

    })
    public TableDataInfo list(OrdersItem ordersItem)
    {
        startPage();
        List<OrdersItem> list = ordersItemService.selectOrdersItemList(ordersItem);
        return getDataTable(list);
    }

    /**
     * 导出订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:ordersItem:export')")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrdersItem ordersItem)
    {
        List<OrdersItem> list = ordersItemService.selectOrdersItemList(ordersItem);
        ExcelUtil<OrdersItem> util = new ExcelUtil<OrdersItem>(OrdersItem.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ordersItem:query')")
    @GetMapping(value = "/{ordersItemId}")
    public AjaxResult getInfo(@PathVariable("ordersItemId") Long ordersItemId)
    {
        return success(ordersItemService.selectOrdersItemByOrdersItemId(ordersItemId));
    }

    /**
     * 新增订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:ordersItem:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "ordersId", value = "所属订单", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skuId", value = "所属规格", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "name", value = "名称", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "skuName", value = "规格名", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "price", value = "单价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "num", value = "数量", dataType = "Long", dataTypeClass = Long.class),
    })
    public AjaxResult add(@RequestBody OrdersItem ordersItem)
    {
        return toAjax(ordersItemService.insertOrdersItem(ordersItem));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:ordersItem:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiImplicitParams({
                    @ApiImplicitParam(name = "createBy", value = "创建者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "createTime", value = "创建时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "updateBy", value = "更新者", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "updateTime", value = "更新时间", dataType = "Date", dataTypeClass = Date.class),
                    @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "ordersId", value = "所属订单", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "productId", value = "所属商品", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "skuId", value = "所属规格", dataType = "Long", dataTypeClass = Long.class),
                    @ApiImplicitParam(name = "name", value = "名称", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "skuName", value = "规格名", dataType = "String", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "price", value = "单价", dataType = "BigDecimal", dataTypeClass = BigDecimal.class),
                    @ApiImplicitParam(name = "num", value = "数量", dataType = "Long", dataTypeClass = Long.class),
    })
    public AjaxResult edit(@RequestBody OrdersItem ordersItem)
    {
        return toAjax(ordersItemService.updateOrdersItem(ordersItem));
    }

    /**
     * 删除订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:ordersItem:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ordersItemIds}")
    public AjaxResult remove(@PathVariable Long[] ordersItemIds)
    {
        return toAjax(ordersItemService.deleteOrdersItemByOrdersItemIds(ordersItemIds));
    }
}
